#include <stdio.h>
#include <stdlib.h>
#include <string.h>


void main001() {
    int a, b, c;
    int max(int x, int y);
    printf("input a and b:");
    scanf("%d,%d", &a, &b);
    c = max(a, b);
    printf("\nmax=%d", c);
}

int max(int x, int y) {
    int z;
    if (x > y) z = x;
    else z = y;
    return (z);
}


void main003() {
    char c1, c2;
    c1 = 'a';
    c2 = 'b';
    printf("%c,%c\n", c1, c2);
    printf("%d,%d\n", c1, c2);
}


void main004() {
    int a, b;
    float d, e;
    char c1, c2;
    double f, g;
    long n, m;
    unsigned p, q;
    a = 61;
    b = 62;
    c1 = 'a';
    c1 = 'b';
    d = 3.56;
    e = -6.87;
    f = 3156.890121;
    g = 0.123456789;
    m = 50000;
    n = -60000;
    p = 32768;
    q = 40000;
    printf("a=%d,b=%d\nc1=%c,c2=%c\nd=%6.2f,e=%6.2f\n", a, b, c1, c2, d, e);
    printf("f=%15.6f,g=%15.12f\nm=%ld,n=%ld\np=%u,q=%u\n", f, g, m, n, p, q);
}


void main005() {
    int a, b;
    unsigned c, d;
    long e, f;
    a = 100;
    b = -100;
    e = 50000;
    f = 32767;
    c = a;
    d = b;
    printf("%d,%d\n", a, b);
    printf("%u,%u\n", a, b);
    printf("%u,%u\n", c, d);
    c = a = e;
    d = b = f;
    printf("%d,%d\n", a, b);
    printf("%u,%u\n", c, d);
}


void main006() {
    char c1 = 'C', c2 = 'h', c3 = 'i', c4 = 'n', c5 = 'a';
    c1 = c1 + 4;
    c2 = c2 + 4;
    c3 = c3 + 4;
    c4 = c4 + 4;
    c5 = c5 + 4;
    printf("%c%c%c%c%c\n", c1, c2, c3, c4, c5);
}


void main007() {
    int i, j, m, n;
    i = 8;
    j = 10;
    printf("%d,%d\n", i++, j--);
    m = i--;
    n = --j;
    printf("%d,%d\n", m, n);
}


#define PI 3.14159

int main008() {
    float r, h;
    double L, s1, s2, v1, v2;
    printf("输入圆半径和圆柱高");
    scanf("%f%f", &r, &h);
    L = 2 * PI * r;
    s1 = PI * r * r;
    s2 = 4 * PI * r * r / 3;
    v1 = s1 * h;
    v2 = 4 * PI * r * r * r;
    printf("圆周长:%lf、圆面积:%lf、圆球表面积:%lf、圆球体体积:%lf圆柱体体积:%lf,", L, s1, s2, v1, v2);

    return 0;
}


int main009() {
    char c1, c2;
    c1 = getchar();
    c2 = getchar();
    putchar(c1);
    putchar(c2);
    printf("\n%c%c", c1, c2);


    return 0;
}


int main010() {
    int x, y;
    scanf("%d", &x);
    if (x < 1) y = x;
    else if (x >= 10) y = 3 * x - 11;
    else y = 2 * x - 1;
    printf("y=%d", y);

    return 0;
}


int main012() {
    float score;
    printf("输入分数（0~100）");
    char grade;
    scanf("%f", &score);
    if ((score >= 90) && (score <= 100))
        grade = 'A';
    else if ((score >= 80) && (score < 90))
        grade = 'B';
    else if ((score >= 70) && (score < 80))
        grade = 'C';
    else if ((score >= 60) && (score < 70))
        grade = 'D';
    else
        grade = 'E';
    printf("%c", grade);

    return 0;
}


int main013() {
    float score;
    char grade;
    while (1) {
        printf("输入分数（0~100）");
        scanf("%f", &score);
        //switch (int(score/10))
        //{
        //    case 10:
        //    case 9:
        //        grade = 'A';
        //    break;
        //    case 8:
        //        grade = 'B';
        //    break;
        //    case 7:
        //        grade = 'C';
        //    break;
        //    case 6:
        //        grade = 'D';
        //    break;
        //    default:
        //        grade = 'E';
        //}
        printf("%c", grade);
    }
    return 0;
}


int main014() {
    int n, n1, n2, n3, n4, n5;
    printf("输入一个不多于５位的正整数:\n");
    scanf("%d", &n);
    if ((n >= 10000) && (n <= 99999)) {
        printf("输入了一个五位的整数\n");
        n1 = n / 10000;
        n2 = n % 10000 / 1000;
        n3 = n % 10000 % 1000 / 100;
        n4 = n % 10000 % 1000 % 100 / 10;
        n5 = n % 10000 % 1000 % 100 % 10;
        printf("顺序：%1d%1d%1d%1d%1d\n", n1, n2, n3, n4, n5);
        printf("逆序：%1d%1d%1d%1d%1d\n", n5, n4, n3, n2, n1);

    } else if ((n >= 1000) && (n <= 9999)) {
        printf("输入了一个四位的整数\n");
        n1 = n / 1000;
        n2 = n % 1000 / 100;
        n3 = n % 1000 % 100 / 10;
        n4 = n % 1000 % 100 % 10;

        printf("顺序：%1d%1d%1d%1d\n", n1, n2, n3, n4);
        printf("逆序：%1d%1d%1d%1d\n", n4, n3, n2, n1);

    } else if ((n >= 100) && (n <= 999)) {
        printf("输入了一个三位的整数\n");
        n1 = n / 100;
        n2 = n % 100 / 10;
        n3 = n % 100 % 10;

        printf("顺序：%1d%1d%1d\n", n1, n2, n3);
        printf("逆序：%1d%1d%1d\n", n3, n2, n1);

    } else if ((n >= 10) && (n <= 99)) {
        printf("输入了一个二位的整数\n");
        n1 = n / 10;
        n2 = n % 10;

        printf("顺序：%1d%1d\n", n1, n2);
        printf("逆序：%1d%1d\n", n2, n1);

    } else if ((n >= 0) && (n <= 9)) {
        printf("输入了一个一位的整数\n");
        n1 = n % 10;

        printf("顺序：%1d\n", n1);
        printf("逆序：%1d\n", n1);

    } else printf("输入错误\n");
    return 0;
}


void main015() {
    int a, b, c, d, t;
    printf("输入四个整数：\n");
    scanf("%d%d%d%d", &a, &b, &c, &d);
    if (a > b) {
        t = a;
        a = b;
        b = t;
    }
    if (a > c) {
        t = a;
        a = c;
        c = t;
    }
    if (a > d) {
        t = a;
        a = d;
        d = t;
    }
    if (b > c) {
        t = b;
        b = c;
        c = t;
    }
    if (b > d) {
        t = b;
        b = d;
        d = t;
    }
    if (c > d) {
        t = c;
        c = d;
        d = t;
    }
    printf("输出从小到大的四个整数：%d %d %d %d", a, b, c, d);


}


void main016() {
    int m, n, t, r, tm, tn;
    printf("输入两个正整数");
    scanf("%d%d", &m, &n);
    if (m < n) {
        t = n;
        n = m;
        m = t;
    }
    tm = m;
    tn = n;
    r = m % n;
    while (r) {
        m = n;
        n = r;
        r = m % n;
    }
    printf("最大公约数%d\n最小公倍数%d", n, tm * tn / n);

}


void main017() {
    int jiechen(int n);
    int i, p;
    double e = 1, t = 0;
    for (i = 1; t <= 1E-7; i++) {

        e += t;
        p = jiechen(i);
        t = 1.0 / p;
    }
    printf("e=%6.6f", e);
}

int jiechen(int n) {
    int s;
    if (n == 1) s = n;
    else s = jiechen(n - 1) * n;
    return (s);
}


void main018() {
    int i;
    double e, p, t;
    e = 1;
    t = 1;
    p = 1;
    i = 1;
    while (t >= 1E-7) {
        e = e + t;
        p = p * i;
        t = 1.0 / p;
        i++;
    }
    printf("%8.6f", e);
}


void main019() {
    int n, i, sum = 0;
    scanf("%d", &n);
    for (i = 1; i <= n; i++)
        if (i % 3 == 0 || i % 7 == 0)
            sum += i;
    printf("%d", sum);
}


void main020() {
    int n, i = 0, sum = 0;
    scanf("%d", &n);
    while (i <= n) {
        if (i % 3 == 0 || i % 7 == 0)
            sum += i;
        i++;
    }
    printf("%d", sum);
}


void main021() {
    int i, x;
    x = 1;
    for (i = 9; i >= 1; i--)
        x = 2 * x + 1;
    printf("%d", x);


}


void main022() {
    int a[10];
    int i, j, min, t;
    for (i = 0; i < 10; i++)
        scanf("%d", &a[i]);

    for (i = 0; i < 10; i++) {
        min = i;
        for (j = i + 1; j <= 10; j++)
            if (a[min] > a[j])
                min = j;
        t = a[i];
        a[i] = a[min];
        a[min] = t;
    }
    for (i = 0; i < 10; i++)
        printf(" %d", a[i]);


}

#define N 15

int main023() {
    int a[N];
    int i, j, k, t;
    printf("输入数组\n");
    for (k = 0; k < N; k++)
        scanf("%d", &a[k]);
    for (i = 0; i < N - 1; i++)
        for (j = i + 1; j < N; j++)
            if (a[i] > a[j]) {
                t = a[i];
                a[i] = a[j];
                a[i] = t;
            }
    int flag = 1, sign = 1;
    int number;
    int loca, top, bott, mid;
    char c;
    while (flag) {
        printf("输入要找的数\n");
        scanf("%d", &number);
        loca = 0;
        top = 0;
        bott = N - 1;
        if ((number < a[0]) || (number > a[N - 1]))
            loca = -1;
        while ((sign == 1) && (top <= bott) && (loca >= 0)) {
            mid = (bott + top) / 2;
            if (number == a[mid]) {
                loca = mid;
                printf("\n找到了,数%d在数组的第%d位.\n", number, loca + 1);
                sign = 0;
            } else if (number < a[mid])
                bott = mid - 1;
            else
                top = mid + 1;
        }
        if (sign == 1 || loca == -1)
            printf("\n查无此数\n");
        printf("是否继续查找？(Y/N)\n");
        scanf(" \n%c", &c);
        printf("\n");
        if (c == 'N' || c == 'n')
            flag = 0;
        else sign = 1;
    }
    return 0;
}


void main024() {
    char s1[20] = "fgjnhdf", s2[40] = "rnstgnsk";
    int i = 0, j = strlen(s1) + 1;
    while (s1[i] != '\0')
        s2[j++] = s1[i++];
    s2[j] = '\0';
    puts(s2);
}


void main025() {
    int i, j;
//	int a[3][4]={9,80,205,40,90,-60,96,1,210,-3,101,89};
    int a[4][4] = {{9,   80,  205, 40},
                   {90,  -60, 96,  1},
                   {210, -3,  101, 89},
                   {45,  54,  156, 7}};
/*    int a[4][4];
	for (i=0;i<4;i++)
		for (j=0,j<4;j++)
			scanf("%d",&a[i][j]);
*/
    int flag1, flag2 = 0, max, maxj, k;
    for (i = 0; i < 4; i++) {
        max = a[i][0];
        maxj = 0;

        for (j = 1; j < 4; j++)
            if (max < a[i][j]) {
                maxj = j;
                max = a[i][maxj];
            }
        for (k = 0, flag1 = 1; k < 4 && flag1; k++)
            if (max > a[k][maxj]) flag1 = 0;
        if (flag1) {
            printf("\n第%d行第%d列的%d是鞍点\n", i + 1, maxj + 1, max);
            flag2 = 1;
        }
    }
    if (!flag2) printf("\n矩阵中无鞍点\n");
}


void main027() {
    int prime(int n);
    int n;
    while (1) {
        printf("输入一个整数");
        scanf("%d", &n);
        if (prime(n)) printf("是素数\n");
        else printf("不是素数\n");
    }


}

int prime(int n) {
    if (n < 2) return 0;
    else
        for (int i = 2; i < n / 2; i++)
            if (n % i == 0) return 0;
            else return 1;
}

void main028() {
    int longest(char string[]);
    char string[100] = {"I love you however you do not love me"};
    longest(string);

}

int longest(char *string) {
    int len = 0, i, n, length = 0, flag = 1, place = 0, point;
    n = strlen(string);
    for (i = 0; i <= n; i++)
        if (string[i] != ' ')
            if (flag) {
                point = i;
                flag = 0;
            } else len++;
        else {
            flag = 1;
            if (len > length) {
                length = len;
                place = point;
                len = 0;
            }
        }

    printf("最长单词的起始位置:%d\n最长单词的长度:%d\n", place + 1, length - 1);
    int j;
    for (j = place; j <= place + length - 2; j++)
        printf("%c", string[j]);

    return 0;

}


void main029() {
    void convert(int n);
    int num;
    scanf("%d", &num);
    convert(num);
}

void convert(int n) {
    int i;
    if ((i = n / 10) != 0)
        convert(i);
    putchar(n % 10 + '0');

}


void main030() {
    int hcf(int u, int v);
    int u, v, n;
    printf("输入两个正整数");
    scanf("%d%d", &u, &v);
    n = hcf(u, v);
    printf("最大公约数%d\n最小公倍数%d", n, u * v / n);

}

int hcf(int u, int v) {
    int t, r;
    if (v > u) {
        t = u;
        u = v;
        v = t;
    }
    while ((r = u % v) != 0) {
        u = v;
        v = r;
    }
    return (v);
}


int v;

void main31() {
    void hcf(int u);
    int u, n;
    printf("输入两个正整数");
    scanf("%d%d", &u, &v);
    n = v;
    hcf(u);
    printf("最大公约数%d\n最小公倍数%d", v, u * n / v);

}



void main032() {
    char s[20];
    int i, n = 0;
    printf("输入一个十六进制数:");
    gets(s);
    for (i = 0; i < strlen(s); i++) {
        if (s[i] > '0' && s[i] <= '9')
            n = n * 16 + s[i] - '0';
        if (s[i] >= 'a' && s[i] <= 'f')
            n = n * 16 + s[i] - 'a' + 10;
        if (s[i] >= 'A' && s[i] <= 'F')
            n = n * 16 + s[i] - 'A' + 10;
    }
    printf("%d", n);
}

